var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

// 导入cors包
const cors = require('cors');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
//导入blogs路由
const blogsRouter = require('./routes/blogs');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// 注册全局中间件
app.use(cors());

app.use('/', indexRouter);
app.use('/users', usersRouter);

//注册blogs
app.use('/blogs', blogsRouter);

module.exports = app;
